package com.hr;

import org.springframework.stereotype.Service;

import com.googlecode.cswish.annotation.GenericType;
import com.googlecode.cswish.annotation.ParamScope;
import com.googlecode.cswish.annotation.Rest;
import com.googlecode.cswish.model.PageElements;
import com.googlecode.cswish.struts.Action;

@Service
public class SalaryAdjItemService extends SalaryItemBaseService{
	
	@Rest(simpleServiceName="espirit.hr.salaryItemBase", type=Action.ADD)
	public void _add(SalaryAdjItem model, @ParamScope(visible=false, value="#ps")PageElements ps, Integer salaryId){
		ps.setElementReadOnly("model.acctTerm.id", true);
		ps.setElementReadOnly("model.employee.id", false);
		ps.setElementVisible("model.acctItem.id", false);
		if (salaryId != null ){
			Salary salary = genericService.load(Salary.class, salaryId);
			if (salary != null){
				model.setEmployee(salary.getEmployee());
				model.setAcctTerm(salary.getAcctTerm());
				ps.setElementReadOnly("model.employee.id", true);
			}
		} else {
			model.setAcctTerm(hrSettingService.getHrSetting().getCurrentAcctTerm());
		}
	}
	
	@Override
	@Rest(simpleServiceName="espirit.hr.salaryItemBase", type=Action.ADD)
	public void add(@GenericType Object model) {
		super.add(model);
	}
	
	@Rest(simpleServiceName="espirit.hr.salaryItemBase", type=Action.UPDATE)
	public void _update(SalaryAdjItem model, @ParamScope(visible=false, value="#ps")PageElements ps){
		ps.setElementReadOnly("model.acctTerm.id", true);
		ps.setElementReadOnly("model.employee.id", true);
		ps.setElementReadOnly("model.acct.id", true);
		ps.setElementVisible("model.acctItem.id", false);
		genericService.view(model);
	}
	
	@Override
	@Rest(simpleServiceName="espirit.hr.salaryItemBase", type=Action.UPDATE)
	public void update(@GenericType Object model) {
		super.update(model);
	}
}
